﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using University.Workshop.Business;

namespace University.Workshop.Presenters.Kardex.Search
{
    public class PresenterSeachKardex
    {
        private ISearchKardexView view;

        public PresenterSeachKardex(ISearchKardexView View)
        {
            view = View;
        }

        public void SearchKardex()
        {
            try
            {
                var k = new Model.Kardex()
                                     {
                                         Person =
                                             new Model.Person()
                                                 {
                                                     PersonId = view.PersonIdRelative,
                                                     LastNames = view.PersonLastNamesRelative,
                                                     Names = view.PersonNamesRelative
                                                 }
                                     };
                view.KardexFinded = ManagerKardex.SearchKardexByParameter(k, view.StateKardex);
            }
            catch (Exception ex)
            {
                view.KardexFinded = null;
                view.NotifyErrorMessage(ex.Message);
            }
        }

        public void ShowDisableKardex()
        {
            view.OpenDisableKardexPopUp(ManagerKardex.GetKardexByKardexId(view.KardexSelected));
            KardexForDisable = view.KardexSelected;
        }

        public void EnableKardex()
        {
            view.GoToModifyKardex(ManagerKardex.GetKardexByKardexId(view.KardexSelected));
        }

        public void DisableKardex()
        {
                ManagerKardex.DisableKardex(KardexForDisable);
                KardexForDisable = null;
                HideDisableKardex();
                ClenSearch();
        }

        public void HideDisableKardex()
        {
            view.HideDisableKardex();
        }

        private void ClenSearch()
        {
            view.PersonIdRelative = string.Empty;
            view.KardexFinded = new Collection<Model.Kardex>();
            view.PersonLastNamesRelative = string.Empty;
            view.PersonNamesRelative = string.Empty;
        }

        public Model.Kardex KardexForDisable { get; set; }

        public void ModifyKardex()
        {
            view.GoToModifyKardex(ManagerKardex.GetKardexByKardexId(view.KardexSelected));
        }



        public void CreateReport()
        {
            view.ShowReportKardex();
        }

        public void HideReportKardex()
        {
            view.HideReportKardex();
        }

        public void ShowReport()
        {
            List<int> years = ManagerKardex.GetAllPosibleYearsOfKardexReadingControl(view.KardexSelected);
            int yearSelected = 2012;
            ManagerKardex.CreateAndOpenKardex(view.KardexSelected, view.YearReportSelected);
            view.HideReportKardex();
        }
    }
}
